home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 1.iso / util / thedit20.zip / uncomm.the < prev    next >
Text File  |  1995-01-26  |  5KB  |  117 lines

  1. /*
  2. $Id: UNCOMM.THE 2.0 1995/01/26 16:34:44 MH Release MH $
  3. */
  4. /***********************************************************************/
  5. /* Description: REXX macro to uncomment lines.                         */
  6. /* Syntax:      uncomm [target]                                        */
  7. /* Notes:       This macro will uncomment lines based on the file      */
  8. /*              type or file name as per below:                        */
  9. /*               .c       - /* */                                      */
  10. /*               .h       - /* */                                      */
  11. /*               .rex     - /* */                                      */
  12. /*               .rexx    - /* */                                      */
  13. /*               .pas     - (* *)                                      */
  14. /*               .asm     - ;                                          */
  15. /*               makefile - #                                          */
  16. /*               Makefile - #                                          */
  17. /*              Full XEDIT/KEDIT/THE targets are supported.            */
  18. /***********************************************************************/
  19. Trace o
  20. arg1 = Arg(1)
  21. noargs = Arg()
  22. forward = 1                  /* assume direction is forward by defualt */
  23. If noargs = 0 Then arg1 = '1'               /* no args - assume 1 line */
  24. 'EXTRACT /LINE/SIZE/STAY/FTYPE/FNAME/LINEND'      /* get various stuff */
  25. current_line = line.1                   /* save current line for later */
  26. reply = valid_target(arg1)                 /* validate supplied target */
  27. If reply = 'ERROR' Then
  28.    Do
  29.      'EMSG Error: 17 Invalid target' arg1
  30.      Exit
  31.    End
  32. If reply = 'NOTFOUND' Then
  33.    Do
  34.      'EMSG Error: 17 Target not found' arg1
  35.      Exit
  36.    End
  37. start_line = Word(reply,1)                        /* get starting line */
  38. nolines = Word(reply,2)                         /* get number of lines */
  39. If nolines < 0 Then Do                /* if target before current line */
  40.    forward = 0                    /* indicate direction to be backward */
  41.    nolines = nolines * -1                     /* make nolines positive */
  42. End
  43. ':'||start_line                                    /* go to first line */
  44. totlines = 0                             /* reset changed line counter */
  45. Select
  46.   When ftype.1 = 'c' Then Do
  47.                      first_comment = '/*'
  48.                      last_comment = '*/'
  49.                      End
  50.   When ftype.1 = 'h' Then Do
  51.                      first_comment = '/*'
  52.                      last_comment = '*/'
  53.                      End
  54.   When ftype.1 = 'rex' Then Do
  55.                      first_comment = '/*'
  56.                      last_comment = '*/'
  57.                      End
  58.   When ftype.1 = 'rexx' Then Do
  59.                      first_comment = '/*'
  60.                      last_comment = '*/'
  61.                      End
  62.   When ftype.1 = 'pas' Then Do
  63.                      first_comment = '(*'
  64.                      last_comment = '*)'
  65.                      End
  66.   When ftype.1 = 'asm' Then Do
  67.                      first_comment = ';'
  68.                      last_comment = ''
  69.                      End
  70.   When ftype.1 = 'asm' Then Do
  71.                      first_comment = 'rem '
  72.                      last_comment = ''
  73.                      End
  74.   When fname.1 = 'makefile' Then Do
  75.                      first_comment = '#'
  76.                      last_comment = ''
  77.                      End
  78.   When fname.1 = 'Makefile' Then Do
  79.                      first_comment = '#'
  80.                      last_comment = ''
  81.                      End
  82.   Otherwise Do
  83.                      first_comment = '/*'
  84.                      last_comment = '*/'
  85.                      End
  86. End
  87. If fname.1 = 'makefile' |  fname.1 = 'Makefile' Then 'SET LINEND OFF'
  88. Do nolines
  89.    start = 0; end = 0
  90.    'EXTRACT /CURLINE/TOF/EOF/'       /* get current line contents, etc.*/
  91.    If tof.1 = 'ON',                    /* ignore line if on TOF or EOF */
  92.    |  eof.1 = 'ON' Then nop
  93.    Else
  94.       Do
  95.         linelength = Length(curline.3)
  96.         len1 = Length(first_comment)
  97.         len2 = Length(last_comment)
  98.         If Substr(curline.3,1,len1) = first_comment Then start = 1
  99.         newlength = linelength - len2 + 1
  100.         If Substr(curline.3,newlength,len2) = last_comment Then end = 1
  101.         If start = 1 & end = 1 Then 
  102.            Do
  103.              newlength = linelength - (len1 + len2)
  104.              newline = Substr(curline.3,len1+1,newlength)
  105.              'REPLACE' newline
  106.              totlines = totlines + 1
  107.            End
  108.       End
  109.    If forward = 1 Then 'N'
  110.    Else 'U'
  111.    If rc \= 0 Then Leave
  112. End
  113. If fname.1 = 'makefile' |  fname.1 = 'Makefile' Then 'SET LINEND' linend.1 linend.2
  114. 'EMSG' totlines 'lines uncommented'      /* say how many lines changed */
  115. If stay.1 = 'ON' Then ':'||current_line
  116. Return                                               /* go back to THE */
  117.